<template>
  <div>
    <img class="user-poster" src="../../icons/img1.png">
    <div v-if="hiddentag">
      <van-divider />
      <van-button type="primary" size="large" to="/login">请登录</van-button>
      <van-divider />
      <van-button type="info" size="large" to="/register">注册新用户</van-button>
      <van-divider />
      <van-button type="warning" size="large" to="/updatepwd">忘记密码</van-button>
      <van-divider />
    </div>
    <div v-else>
      <van-contact-card type="edit" :name="sysUser.username" :tel="sysUser.mobile" :editable="false" />
      <van-divider />
      <van-button type="warning" size="large" to="/updatepwd">修改密码</van-button>
      <van-divider />
      <van-button type="danger" size="large" @click="logout()">退出登录</van-button>
    </div>

  </div>
</template>

<script>
import sysuser from '@/api/sysuser'
import Cookies from 'js-cookie'
export default {
  name: 'Tologin',
  data() {
    return {
      hiddentag: true,
      sysUser: {
        username: '',
        mobile: ''
      }
    }
  },
  mounted() {
    if (Cookies.get('Sysid')) {
      this.hiddentag = false
      this.getById()
    }
  },
  methods: {
    getById() {
      sysuser.getById(Cookies.get('Sysid')).then(response => {
        this.sysUser = response.data.item
      })
    },
    async logout() {
      await this.$store.dispatch('user/logout').then(() => {
        this.$router.replace({ path: '/' })
      }).catch(() => {

      })
    }
  }

}
</script>

<style scoped>

</style>
